package com.maybach.dubbo.api;

import java.io.Serializable;
import java.util.Map;

/**
 * Created by weishuai on 16/1/8.
 */
public class BizResult<T> implements Serializable {
	private static final long serialVersionUID = 6853724972L;

	public boolean success = false;
	private T result;
	public String code;
	public String msg;

	public Map<String, Object> extraInfo;

	public static <T> BizResult<T> create() {
		return new BizResult<T>();
	}

	public static <T> BizResult<T> create(T data) {
		BizResult<T> result = create();
		result.setSuccess(true);
		result.setResult(data);
		return result;
	}

	public static <T> BizResult<T> create(String code, String msg) {
		BizResult<T> result = create();
		result.setSuccess(false);
		result.setCode(code);
		result.setMsg(msg);
		return result;
	}

	public Map<String, Object> getExtraInfo() {
		return extraInfo;
	}

	public void setExtraInfo(Map<String, Object> extraInfo) {
		this.extraInfo = extraInfo;
	}

	public BizResult() {
		this.success = true;// 默认true
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getCode() {
		return code;
	}

	// 只要有错误码为false
	public void setCode(String code) {
		this.success = false;
		this.code = code;
	}

	public T getResult() {
		return result;
	}

	public void setResult(T result) {
		this.result = result;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.success = false;// 有错误信息为false
		this.msg = msg;
	}

}
